
const { AsyncSeriesWaterfallHook } = require("tapable"); //异步串行瀑布钩子
const hook = new AsyncSeriesWaterfallHook(["name", "age"]);
console.time("cost");
hook.tapPromise("1", (name, age) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log('1',name,age);
      resolve('result1');
    }, 1000);
  });
});
hook.tapPromise("2", (name, age) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log('2',name,age);
      resolve();
    }, 2000);
  });
});
hook.tapPromise("3", (name, age) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log('3',name,age);
      resolve('result3');
    }, 3000);
  });
});
hook.promise("zhufeng", 12).then((result) => {
  console.log(result);
  console.timeEnd("cost");
});
// ==》
// 1 zhufeng 12
// 2 result1 12
// 3 result1 12
// result3
// cost: 6.021s
